import java.util.Scanner;

public class GameHandler {
	Scanner input = new Scanner(System.in);
	Overworld tempWorld = new Overworld();
	 
	public GameHandler(){
		
	}
	
	public void playGame(){
		HexMovement();
	}
	
	public void HexMovement(){
		boolean flag = true;
		System.out.println("Current Hex: " + tempWorld.getCurrentLocation()+"\n");
		//tempWorld.showNeighbors();
		
		while(flag){
			if(tempWorld.currentArea == null){
				System.out.print("Which direction:");
				String response = getResponse();
				System.out.println("\nMoving " + response);
				tempWorld.moveOverWorldDirection(response);
				System.out.println("Current Location:" + tempWorld.getCurrentLocation());
			}
			else{
				//Get Tile area
				AreaMovement(null);
			}
		}	
	}
	
	public void AreaMovement(Area area){
		boolean flag = true;
		
		while(flag){
			String response = getResponse();
			if(checkForDirection(response)){
				char[] temp = response.toCharArray();
				System.out.println(tempWorld.city.moveCharacter(temp[0]));
			}
			else if(response.startsWith("open") && response.length() > 4){
				tempWorld.currentArea.open(response);
			}
			else if(response.startsWith("close") && response.length() > 5){
				tempWorld.currentArea.close(response);
			}
		}	
	}
	
	public String getResponse(){
		try{
			return input.nextLine().trim().toLowerCase();
		}
		catch(Exception e){
			return "You need to put in a valid response";
		}
	}
	
	public boolean checkForDirection(String directionString){
		if(directionString.toLowerCase().equals("east") || directionString.toLowerCase().equals("west") || directionString.toLowerCase().equals("north") || directionString.toLowerCase().equals("south")
				|| directionString.toLowerCase().equals("up") || directionString.toLowerCase().equals("down") || directionString.toLowerCase().equals("e") || directionString.toLowerCase().equals("w")
				 || directionString.toLowerCase().equals("n") || directionString.toLowerCase().equals("s") || directionString.toLowerCase().equals("u") || directionString.toLowerCase().equals("d"))
			return true;
		else
			return false;
	}
}
